package com.weixing.mall.provider.controller.rpc;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.provider.api.model.vo.OrderAgentVo;
import com.weixing.mall.provider.model.domain.OrderAgent;
import com.weixing.mall.provider.service.IOrderAgentService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author wx
 * @Date 2019/12/4 15:44
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/orderagent")
public class OrderAgentRpcController {
    @Autowired
    private IOrderAgentService orderAgentService;


    @GetMapping("/selectByOrderId")
    public Result<List<OrderAgentVo>> selectByOrderId(Long orderId) {
        QueryWrapper<OrderAgent> wrapper = new QueryWrapper<OrderAgent>();
        wrapper.eq("order_id", orderId);
        List<OrderAgent> orderAgents = orderAgentService.list(wrapper);
        List<OrderAgentVo> list = Lists.newArrayList();
        if (CollUtil.isNotEmpty(orderAgents)) {
            OrderAgentVo vo = null;
            for (OrderAgent agent : orderAgents) {
                vo = new OrderAgentVo();
                BeanUtils.copyProperties(agent, vo);
                list.add(vo);
            }
        }
        return ResultUtil.success(list);
    }
}
